<?php
$html_template = <<<HEAD
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{t}</title>
</head>
<body>
{b}
</body>
</html>
HEAD;

/**
 * 
 * Erzeugt einen Hyperlink
 * @param unknown_type $name displayname des links
 * @param unknown_type $destination ziel url
 * @param unknown_type $query_string ggf get parameter uebergeben
 * @return string
 */
function add_link($name, $destination="", $query_string="")
{
		$destination = $destination ? $destination : $name;
		$query_string = $query_string ? "?".$query_string : "";
		return "<a href='$destination.php$query_string'>$name</a><br />\n";
}

$exercises = array("quad", "fragebogen");
$title = "INDEX";
$body = "";

/**
 * 
 * fuellt links in index seite aus $exercises liste
 */
function get_links($exercises)
{
	$body = "";
	foreach ($exercises as $e)
	{
		$body .= add_link($e);
	}
	return $body;
}

$body .= add_link("quadn", "quad", "n=5");
$body .= get_links($exercises);

echo str_replace(array("{t}", "{b}"), array($title, $body), $html_template);